package com.smartstate.dataManagement.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.smartstate.dataManagement.dto.EquipmentDTO;
import com.smartstate.dataManagement.dto.PageDTO;
import com.smartstate.dataManagement.entity.Equipment;
import com.smartstate.dataManagement.service.EquipmentService;
import com.smartstate.dataManagement.vo.ResultVO;
import io.swagger.annotations.ApiOperation;
import org.quartz.SchedulerException;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.io.Serializable;
import java.util.List;


@RestController
@RequestMapping("/Equipment")
@ApiOperation("设备控制层")
public class EquipmentController implements Serializable {

    @Resource
    private EquipmentService equipmentService;

    @PostMapping("/save")
    @ApiOperation(value = "新增设备")
    public ResultVO<Boolean> saveOrUpdate(@RequestBody EquipmentDTO equipment) throws Exception {
        return ResultVO.ok(equipmentService.save(equipment));

    }

    @DeleteMapping("/removeByIds")
    @ApiOperation(value = "根据ID批量删除")
    public boolean removeByIds(@RequestBody List<Equipment> item) {
        return equipmentService.removeByIds(item);
    }

    @DeleteMapping("/removeById")
    @ApiOperation(value = "根据ID删除")
    public boolean removeById(@RequestParam String id) throws SchedulerException {
        // 删除设备，对象表和设备配置表也要删
        return equipmentService.removeDeviceById(id);
    }

    @PostMapping("/pageEquipment")
    @ApiOperation(value = "单表分页查询")
    public Page<Equipment> pageEquipment(@RequestBody PageDTO<Equipment> pageDTO) {
        return equipmentService.queryAllPageByDTO(pageDTO);
    }

    @PostMapping("/additionalAttribute")
    @ApiOperation(value = "添加设备附件属性")
    public ResultVO<Boolean> additionalAttribute(@RequestBody EquipmentDTO equipmentDTO) {
        if (equipmentService.additionalAttribute(equipmentDTO) == true){
            return ResultVO.ok(true, "添加成功");
        }else {
            return ResultVO.ok(false, "属性值全为空，添加失败");
        }
    }



    @PostMapping("/selectEquipment")
    @ApiOperation(value = "根据设备类型查设备")
    public ResultVO selectEquipment(String type) {
        return ResultVO.ok(equipmentService.selectEquipment(type));
    }

    @PostMapping("/selectEquipmentType")
    @ApiOperation(value = "查询所有设备中的工业看板")
    public ResultVO selectEquipmentType() {
        return ResultVO.ok(equipmentService.selectEquipmentType());
    }

}
